package com.resource.homeworkmanage.service.impl;

import com.resource.common.utils.PageUtils;
import com.resource.common.utils.Query;
import com.resource.homeworkmanage.entity.TWorkInformationDetailEntity;
import com.resource.homeworkmanage.entity.TWorkInformationEntity;
import com.resource.homeworkmanage.feign.WorkSubmitRemote;
import com.resource.homeworkmanage.mapper.TWorkInformationDetailDao;
import com.resource.homeworkmanage.service.TWorkInformationDetailService;
import com.resource.homeworkmanage.service.TWorkInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;



@Service("tWorkInformationDetailService")
public class TWorkInformationDetailServiceImpl extends ServiceImpl<TWorkInformationDetailDao, TWorkInformationDetailEntity> implements TWorkInformationDetailService {

    @Autowired
    private TWorkInformationService tWorkInformationService;

    @Autowired
    private WorkSubmitRemote workSubmitRemote;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<TWorkInformationDetailEntity> page = this.page(
                new Query<TWorkInformationDetailEntity>().getPage(params),
                new QueryWrapper<TWorkInformationDetailEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public void submitMessage(TWorkInformationDetailEntity tWorkInformationDetail) {
        TWorkInformationEntity workSelect = tWorkInformationService.getOne(new QueryWrapper<TWorkInformationEntity>().eq("work_code", tWorkInformationDetail.getWorkCode()));
        HashMap<String, String> stringMap = new HashMap<>();
        stringMap.put("publishNo",workSelect.getWorkSubmitStudentCode());
        stringMap.put("publishName",workSelect.getWorkSubmitStudentName());
        stringMap.put("publishContent",tWorkInformationDetail.getWorkContent());
        stringMap.put("receiveNo",workSelect.getWorkAuditTeacherCode());
        stringMap.put("receiveName",workSelect.getWorkAuditTeacherName());
        stringMap.put("publishTime",workSelect.getWorkSubmitTime());
        workSubmitRemote.submitNoticeByHomework(stringMap);
    }

    @Override
    public void saveRelateDetail(TWorkInformationEntity tWorkInformation) {
        TWorkInformationDetailEntity tWorkInformationEntity = new TWorkInformationDetailEntity();
        tWorkInformationEntity.setWorkCode(tWorkInformation.getWorkCode());
        tWorkInformationEntity.setWorkName(tWorkInformation.getWorkName());
        tWorkInformationEntity.setWorkContent(tWorkInformation.getWorkContent());
        this.save(tWorkInformationEntity);
    }
}